
package guichatapplication;

import java.awt.Color;
import java.awt.Component;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

public class MessageListRenderer extends JLabel implements ListCellRenderer {
  private static final Color HIGHLIGHT_COLOR = new Color(0, 0, 128);

  public MessageListRenderer() {
    setOpaque(true);
    setIconTextGap(12);
  }

  @Override
  public Component getListCellRendererComponent(JList list, Object value,
    int index, boolean isSelected, boolean cellHasFocus) {
    MessageListCell entry = (MessageListCell) value;
    setText(entry.getMessage());
    setIcon(entry.getImage());
    if(entry.getPosition()==1)
        setHorizontalAlignment(RIGHT);
    else
        setHorizontalAlignment(LEFT);
    if (isSelected) {
      setBackground(new Color(0,128,50));
      setForeground(Color.yellow);
    } else {
      setBackground(new Color(0,128,50));
      setForeground(Color.WHITE);
    }
    return this;
  }
}
